<html>
        <head>
                <title>ResellersPanel</title>
                <meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
                <style>
			body {
				background-attachment: scroll;
				background-position: top;
				background-repeat: repeat-x;
				background-color:#FFFFFF;
				font-family: Tahoma, Helvetica, sans-serif;
                                font-weight: none;
				font-size: 11px;
			}
                        th {
                                height: 20px;
                                background-image: url(images/bg_th.jpg);
                                background-position: top;
                                background-repeat: repeat-x;
                                font-family: Tahoma, Helvetica, sans-serif;
                                font-size: 11px;
                                font-weight: bold;
                                color: #FFFFFF;
                        }

                        .bTable {
                                border-color: #FFC9AD #FFC9AD black black;
                                        border-style: solid;
                                        border-top-width: 1px;
                                        border-right-width: 1px;
                                        border-bottom-width: 0px;
                                        border-left-width: 0px;
                        }

                        .bTable td {
                                padding: 5 5 5 5;
                                        border: #FFC9AD solid;
                                        border-width: 0px 0px 1px 1px;
                                        font-size: 11px;
                                        font-family: Tahoma, Helvetica, sans-serif;
                                        color: #000000;
                                        text-decoration: none
                        }
                        .bTable th {
                                padding: 2px;
                            /*    background-color:#E9E8E0;*/
                                background-color: white;
                                border: #FFC9AD solid;
                                        border-width: 0px 0px 1px 1px;
                                font-size: 11px;
                                font-weight: bold;
                                font-family: Tahoma, Helvetica, sans-serif;
                                color: #0F0F0F;
                                text-decoration: none;

                        }
                        .bTable table{
                                        border-color: #FFC9AD #FFC9AD #FFC9AD #FFC9AD;
                                 border-style: solid;
                                 border-top-width: 1px;
                                 border-right-width: 1px;
                                 border-bottom-width: 0px;
                                 border-left-width: 0px;
                        }
                        .bTable td td {
                                border: 0px;
                                border-bottom: 1px solid;
                                        border-left-width: 1px solid;
                                        border-left-color:#FFC9AD;
                                border-bottom-color:#FFC9AD;
                        }
                        .errormsg{
                                        color: #FF0000;
                                font-size: 12pt;
                                font-family: Verdana, Arial, Helvetica, sans-serif;
                                width: 100%;
                                font-weight: bold;
                        }
                </style>
        </head>
        <body onLoad='window.focus();'>
<?
include('wallet_db.html');
include('../rp2/global_functions.php');
if (!isset($client_id)) {
	exit("<div>No client selected!</div>");
}
$order_cl = 'ORDER BY domain ASC';
if (!isset($by)) $by = 'domain_asc';
switch ($by) {
	case 'domain_desc':
		$order_cl = 'ORDER BY domain DESC';
		break;
	case 'username_asc':
		$order_cl = 'ORDER BY domain ASC';
		break;
	case 'start_d_desc':
		$order_cl = 'ORDER BY start_date DESC';
		break;
	case 'start_d_asc':
		$order_cl = 'ORDER BY start_date ASC';
		break;
	case 'expire_desc':
		$order_cl = 'ORDER BY expire_date DESC';
		break;
	case 'expire_asc':
		$order_cl = 'ORDER BY expire_date ASC';
		break;
	case 'server_asc':
		$order_cl = 'ORDER BY server ASC';
		break;
	case 'server_desc':
		$order_cl = 'ORDER BY server DESC';
		break;
}
//-----------------------------------------------------
	$sql['type'] = "SELECT";
    $sql['params'] = "(d.sld||'.'||d.tld) as domain, c.server, pu.start_date, pu.expire_date,pr.price,pr.wholesale";
    $sql['table'] = "registerdomain as d, purchases as pu, clients as c,products as pr";
    $sql['where'] = "c.client_id='".$client_id."' and c.client_id=pu.client_id and pu.product_id=pr.product_id and pu.purchase_id=d.purchase_id";
    $sql['options'] = "$order_cl";
    $sql['return'] = "query";
    $sql['return'] = "struct";
//------------------------------------------------------
if (!$result=sql_exec($sql,$dbh81,'assoc')) {
	exit("No domains found for this client!");
}
?>
<TABLE border="0" class="bTable">
<tr>
<?
	$acct_expired = '0';
	$acct_expired_wsp = '0.00';
	$acct_expired_retp = '0.00';
	$acct_ab_expired = '0';
	$acct_ab_expired_wsp = '0.00';
	$acct_ab_expired_retp = '0.00';
	$acct_active = '0';
	$acct_active_wsp = '0.00';
	$acct_active_retp = '0.00';
	
	$params['sid'] = $sid;
	$params['action'] = 'showDomains';
	$params['client_id'] = $client_id;
	if ($by == 'domain_asc') {
		$params['by'] = 'domain_desc';
	} else {
		$params['by'] = 'domain_asc';
	}
	$tmpurl = "$baseURL/?".encode_params($params);
	echo "<th><a href='$tmpurl'>Domain</a></th>";
	unset($params,$tmpurl);
		
	$params['sid'] = $sid;
	$params['action'] = 'showDomains';
	$params['client_id'] = $client_id;
	if ($by == 'start_d_asc') {
		$params['by'] = 'start_d_desc';
	} else {
		$params['by'] = 'start_d_asc';
	}
	$tmpurl = "$baseURL/?".encode_params($params);
	echo "<th><a href='$tmpurl'>Start Date</a></th>";
	unset($params,$tmpurl);
	
	$params['sid'] = $sid;
	$params['action'] = 'showDomains';
	$params['client_id'] = $client_id;
	if ($by == 'expire_asc') {
		$params['by'] = 'expire_desc';
	} else {
		$params['by'] = 'expire_asc';
	}
	$tmpurl = "$baseURL/?".encode_params($params);
	echo "<th><a href='$tmpurl'>Expire Date</a></th>";
	unset($params,$tmpurl);
	$params['sid'] = $sid;
	$params['action'] = 'showDomains';
	$params['client_id'] = $client_id;
	if ($by == 'server_asc') {
		$params['by'] = 'server_desc';
	} else {
		$params['by'] = 'server_asc';
	}
	$tmpurl = "$baseURL/?".encode_params($params);
	echo "<th><a href='$tmpurl'>Server</a></th>
	<th>WP</th>
	<th>RP</th>
	</tr>";
	foreach ($result as $value) {
		unset($start_date,$exp_date,$dom,$font,$after_14_days,$wsp,$retp);
		$wsp = $value['wholesale'][12]['USD'];
		$retp = $value['price'][12]['USD'];
		$start_date = strtotime($value['start_date']);
		$exp_date = strtotime($value['expire_date']);
		$after_14_days = strtotime("-14 days",strtotime($value['expire_date']));
		if ($exp_date <= $now_date) {
			$font = "<font color='#FF0000'>";
			$acct_expired ++;
			$acct_expired_wsp += $wsp;
			$acct_expired_retp += $retp;
		} elseif ($now_date >= $after_14_days) {
			$font = "<font color='#FFCC66'>";
			$acct_ab_expired ++;
			$acct_ab_expired_wsp += $wsp;
			$acct_ab_expired_retp += $retp;
		} else {
			$font = "<font color='#000000'>";
			$acct_active ++;
			$acct_active_wsp += $wsp;
			$acct_active_retp += $retp;
		}
		echo "<tr>
			<td>".$font.$value['domain']."</font></td>
			<td>".$font.$value['start_date']."</font></td>
			<td>".$font.$value['expire_date']."</font></td>
			<td>".$font.$value['server']."</font></td>
			<td>".$font.$wsp."</font></td>
			<td>".$font.$retp."</font></td>
		</tr>";
	}
	?>
</table><br><br>
<? 
$acct_total = $acct_ab_expired + $acct_expired + $acct_active;
$acct_total_wsp = $acct_ab_expired_wsp + $acct_expired_wsp + $acct_active_wsp;
$acct_total_retp = $acct_ab_expired_retp + $acct_expired_retp + $acct_active_retp;

echo "<TABLE class='bTable' cellspacing=0>
	<tr>
		<th>Domains</th>
		<th>Number</th>
		<th>WP</th>
		<th>RP</th>
	</tr>
	<tr>
		<td><font color='#FFCC66'>Domains about to expire:</font></td>
		<td align='right'><font color='#FFCC66'>$acct_ab_expired</font></td>
		<td align='right'><font color='#FFCC66'>$".number_format($acct_ab_expired_wsp,2,'.',',')."</font></td>
		<td align='right'><font color='#FFCC66'>$".number_format($acct_ab_expired_retp,2,'.',',')."</font></td>
	</tr>
	<tr>
		<td><font color='#FF0000'>Expired domains:</font></td>
		<td align='right'><font color='#FF0000'>$acct_expired</font></td>
		<td align='right'><font color='#FF0000'>$".number_format($acct_expired_wsp,2,'.',',')."</font></td>
		<td align='right'><font color='#FF0000'>$".number_format($acct_expired_retp,2,'.',',')."</font></td>
	</tr>
	<tr>
		<td>Active domains:</td>
		<td align='right'>$acct_active</td>
		<td align='right'>$".number_format($acct_active_wsp,2,'.',',')."</td>
		<td align='right'>$".number_format($acct_active_retp,2,'.',',')."</td>
	</tr>
	<tr>
		<td><b>Domains total:</b></td>
		<td align='right'><b>$acct_total</b></td>
		<td align='right'><b>$".number_format($acct_total_wsp,2,'.',',')."</b></td>
		<td align='right'><b>$".number_format($acct_total_retp,2,'.',',')."</b></td>
	</tr>
	</table><br>";
?>
<p><b>Legend:</b><br><br><font color='#FFCC66'><b>Yellow:</b></font> All domains , which are <font color='#FFCC66'>ABOUT TO EXPIRE</font> in the next 14 days are marked in yellow<br>
<font color='#FF0000'><b>Red:</b></font> All domains, which are <font color='#FF0000'>EXPIRED ALREADY</font> are marked in red.<br><b>WP:</b> Wholesale Price<br><b>RP: </b>Retail Price</p>
<br><br>[<a href='#' onclick="window.close();">CLOSE THE WINDOW</a>]&nbsp;
[<a href='#' onclick="window.print();">PRINT THE WINDOW</a>]
</BODY>
</HTML>
